package com.westvalley.common.kit;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

public class ListKit {
	public static <T> List<T> getList(T[] objs){
		List<T> list = new ArrayList<T>();
		for(T t : objs){
			list.add(t);
		}
		return list;
	}
	
	public static <T> List<T> getList(Class<T> clazz,Object[] objs){
		List<T> list = new ArrayList<T>();
		for(Object obj : objs){
			list.add(CastKit.cast(clazz, obj));
		}
		return list;
	}
	
	public static <T> List<T> getList(Class<T> clazz,String str,String split){
		return getList(clazz,StringKit.split(str,split));
	}
	
	public static <T> List<T> getList(Class<T> clazz,String str){
		return getList(clazz,StringKit.split(str,","));
	}
	
	public static List<String> toStrList(Object[] objs){
		List<String> list = new ArrayList<String>();
		for(Object obj : objs){
			list.add(obj.toString());
		}
		return list;
	}
	
	public static List<String> toStrList(List<?> listObj){
		List<String> list = new ArrayList<String>();
		for(Object obj : listObj){
			list.add(obj.toString());
		}
		return list;
	}
	
	public static List<String> toStrFieldList(List<Field> listField){
		List<String> list = new ArrayList<String>();
		for(Field field : listField){
			list.add(field.getName().toUpperCase());
		}
		return list;
	}
	
	public static Object[][] list2Array(List<List<Object>> list){
		Object[][] Objects = null;
		if(list!=null){
			Objects = new Object[list.size()][];
			for(int i=0;i<list.size();i++){
				List<Object> listObjs = list.get(i);
				Object[] Objs = new Object[listObjs.size()];
				for(int j=0;j<listObjs.size();j++){
					Objs[j]=listObjs.get(j);
				}
				Objects[i]=Objs;
			}
		}
		return Objects;
	}
	
	public static void main(String[] args) {
		String[] t = {"1","2"};
		System.out.println(ListKit.getList(t));
	}
}
